package com.example.service.impl;

import com.example.MyPritice.DeadLockTestClass;
import com.example.service.JvmStackService;
import org.springframework.stereotype.Service;

@Service
public class  JvmStackServiceImpl implements JvmStackService {
    @Override
    public void deadLock() {
        Object a=new Object();
        Object b=new Object();

        new Thread(()->{
            DeadLockTestClass deadLockTestClass = new DeadLockTestClass(a,b);
            deadLockTestClass.deadLock();
        },"sisuo1").start();
        new Thread(()->{
            DeadLockTestClass deadLockTestClass = new DeadLockTestClass(b,a);
            deadLockTestClass.deadLock();
        },"sisuo2").start();
    }

    @Override
    public void deadCircle(long time) {
        System.out.println("即将死循环");
        while (true){
            try {
                Thread.sleep(time);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
